﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;

public partial class VideoGallery : System.Web.UI.Page
{
    //static LinkButton[] Lbutton = new LinkButton[100];
    //static int btn_count;
    internal class CustomCompare : IComparer<string>
    {
        public int Compare(string x, string y)
        {
            return DateTime.Compare(
              Directory.GetCreationTime(y),Directory.GetCreationTime(x));
        }
    }

    string[] dirrArray2 = new string[1];
    string[] FOlderList = new string[1];
    string[] FOlderList2 = new string[1];

    protected void Page_Load(object sender, EventArgs e)
    {
        //string virtualPathDir = Server.MapPath("~/galerijas/"); // atrod virtual path lapas Bāzes MAPI

        //string[] dirrAray = Directory.GetDirectories(virtualPathDir); // nolasa visas servera Mapes
        //// mapju SORTēšana pēc datuma :) 
        //Array.Resize(ref dirrArray2,dirrAray.Length);

        //int cipars = 0; // Sagrupē mapes tā lai jaunākā ir pēdējā !!
        //for (int i = dirrAray.Length; i > 0; i--)
        //{
        //    dirrArray2[cipars] = dirrAray[i - 1];
        //    cipars++;
        //}
        //Array.Sort(dirrAray, new CustomCompare());
        //string[] FOlderList = new string[dirrAray.Length];
       
        //for (int i = 0; i < dirrAray.Length; i++)
        //{
        //    FOlderList[i] = dirrAray[i].Substring(dirrAray[i].LastIndexOf("\\") + 1);
        //}

        string virtualPathDir2 = Server.MapPath("~/");

        DataTable Mape = new DataTable("Mape");
        Mape.ReadXml(virtualPathDir2 + "Mape.xml");
        Array.Resize(ref FOlderList, Mape.Rows.Count);
        for (int i = 1; i < Mape.Rows.Count; i++)
        {
                FOlderList[i] = Mape.Rows[i][1].ToString().Substring(10);
        }
        Repeater1.DataSource = FOlderList;
        Repeater1.DataBind();
    }

    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int MapesNr = e.Item.ItemIndex;
        //int Nr = dirrArray2.Length - 1 - MapesNr;
        //Response.Redirect("Galery.aspx?value=" + Nr);

        string virtualPathDir2 = Server.MapPath("~/");
        DataTable Mape = new DataTable("Mape");
        Mape.ReadXml(virtualPathDir2 + "Mape.xml");

        int Nr = (int)Mape.Rows[MapesNr][0];
        Response.Redirect("Galery.aspx?value=" + Nr);

    }
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        int MapesNr = e.Item.ItemIndex;
        //int Nr = dirrArray2.Length - 1 - MapesNr;
        //Response.Redirect("Galery.aspx?value=" + Nr);

        string virtualPathDir2 = Server.MapPath("~/");
        DataTable MapeNew = new DataTable("Mape");
        MapeNew.ReadXml(virtualPathDir2 + "MapeNew2013.xml");

        int Nr = (int)MapeNew.Rows[MapesNr][0];
        Response.Redirect("Galery.aspx?value=" + Nr);
    }
}